/* 
    工具类
*/

//格式化时间
export function formatDate(val,type){
    let date = val === null ? new Date() : new Date(val);
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    let h = date.getHours();
    let m = date.getMinutes();
    let s = date.getSeconds();
    if(type === 0){
        return year + "-" + addZero(month) + "-" + addZero(day) + " " + addZero(h) + ":" + addZero(m) + ":" + addZero(s);
    } else if (type === 1){
        return year + "-" + addZero(month) + "-" + addZero(day);
    } else if (type === 2){
        return addZero(h) + ":" + addZero(m) + ":" + addZero(s);
    } else if (type === 3){
        return year + "-" + addZero(month) + "-" + addZero(day) + " 00:00:00";
    }
}

function addZero(val){
    return val > 9 ? val : "0" + val;
}

export async function sleep(seconds = 0){
    return new Promise((resolve,reject) => {
        setTimeout(() => {
            resolve('end');
        }, seconds);
    })
}


/**
 * 通过精致token获取登录用户信息
 * @param token 
 * @returns 用户信息 | 错误提示
 */
export const getUserInfoByToken = (token = null) => {
    const isDevelopment = process.env.NODE_ENV === 'development';
    if(token === null) {
        if(isDevelopment){
            token = process.env.VUE_APP_APPLICATION_TOKEN;
        } else {
            token = localStorage.getItem("Token");
        }
    }
    const strings = token.split('.') //通过split()方法将token转为字符串数组
    //取strings[1]数组中的第二个字符进行解析
    const userinfo = JSON.parse(decodeURIComponent(escape(window.atob(strings[1].replace(/-/g, '+').replace(/_/g, '/')))));
    return userinfo;
}

const array = [
    {
        orderNum:"CPJY25040025",
        status:"生效",
        productName:"C型材GGD",
        productCode:"CP2406046",
        checkResult:"",
        checkTime:"2025-04-10 15:52:46",
        checkNum:"2",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"C型材GGD"
    },
    {
        orderNum:"CPJY25040030",
        status:"生效",
        productName:"低压开关柜",
        productCode:"CP0006",
        checkResult:"",
        checkTime:"2025-04-10 17:20:16",
        checkNum:"4",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"低压开关柜"
    },
    {
        orderNum:"JY20250410000005",
        status:"生效",
        productName:"低压开关柜",
        productCode:"CP0006",
        checkResult:"",
        checkTime:"2025-04-10 16:26:47",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"低压开关柜"
    },
    {
        orderNum:"JY20250410000004",
        status:"生效",
        productName:"低压开关柜",
        productCode:"CP0006",
        checkResult:"",
        checkTime:"2025-04-10 16:26:46",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"低压开关柜"
    },
    {
        orderNum:"CPJY25040023",
        status:"生效",
        productName:"C型材GGD",
        productCode:"CP0006",
        checkResult:"",
        checkTime:"2025-04-10 15:24:14",
        checkNum:"2",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"C型材GGD"
    },
    {
        orderNum:"CPJY25040021",
        status:"生效",
        productName:"C型材GGD",
        productCode:"CP0006",
        checkResult:"",
        checkTime:"2025-04-10 15:24:14",
        checkNum:"2",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"C型材GGD"
    },
    {
        orderNum:"JY20250410000003",
        status:"生效",
        productName:"欧式箱变",
        productCode:"CP0009",
        checkResult:"",
        checkTime:"2025-04-10 10:17:35",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"欧式箱变"
    },
    {
        orderNum:"JY20250410000002",
        status:"生效",
        productName:"欧式箱变",
        productCode:"CP0009",
        checkResult:"",
        checkTime:"2025-02-13 09:05:36",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"欧式箱变"
    },
    {
        orderNum:"JY20250213000001",
        status:"生效",
        productName:"欧式箱变",
        productCode:"CP0009",
        checkResult:"",
        checkTime:"2025-02-13 09:05:34",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"欧式箱变"
    },
    {
        orderNum:"JY20250113000002",
        status:"创建",
        productName:"欧式箱变",
        productCode:"CP0009",
        checkResult:"",
        checkTime:"2025-01-13 08:32:26",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"欧式箱变"
    },
    {
        orderNum:"JY20250113000001",
        status:"生效",
        productName:"欧式箱变",
        productCode:"CP0009",
        checkResult:"",
        checkTime:"2025-01-13 08:32:24",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"欧式箱变"
    },
    {
        orderNum:"JY20241210000018",
        status:"生效",
        productName:"10kV箱式变电站",
        productCode:"CP0005",
        checkResult:"",
        checkTime:"2024-12-10 22:17:13",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"欧式箱变"
    },
    {
        orderNum:"JY20241210000017",
        status:"生效",
        productName:"10kV箱式变电站",
        productCode:"CP0005",
        checkResult:"",
        checkTime:"2024-12-10 21:58:17",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"欧式箱变"
    },
    {
        orderNum:"JY20241210000011",
        status:"生效",
        productName:"低压开关柜",
        productCode:"",
        checkResult:"",
        checkTime:"2024-12-10 16:59:14",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"低压开关柜"
    },
    {
        orderNum:"CPJY24090003",
        status:"生效",
        productName:"欧变内环保柜",
        productCode:"CP2405047",
        checkResult:"合格",
        checkTime:"2024-09-10 13:50:40",
        checkNum:"1",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"欧变内环保柜"
    },
    {
        orderNum:"CPJY24070001",
        status:"生效",
        productName:"低压开关柜",
        productCode:"CP0006",
        checkResult:"合格",
        checkTime:"2024-07-05 13:39:51",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"低压开关柜"
    },
    {
        orderNum:"CPJY24060006",
        status:"生效",
        productName:"欧式箱变",
        productCode:"CP0006",
        checkResult:"合格",
        checkTime:"2024-06-05 16:53:40",
        checkNum:"1",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"欧式箱变"
    },
    {
        orderNum:"CPJY24060004",
        status:"生效",
        productName:"欧式箱变",
        productCode:"CP0006",
        checkResult:"合格",
        checkTime:"2024-06-04 10:00:52",
        checkNum:"1",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"欧式箱变"
    },
    {
        orderNum:"CPJY24060001",
        status:"生效",
        productName:"户外环网箱",
        productCode:"CP2405052",
        checkResult:"合格",
        checkTime:"2024-06-02 17:23:41",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"户外环网箱"
    },
    {
        orderNum:"CPJY24050022",
        status:"生效",
        productName:"欧变内充气柜",
        productCode:"CP2405046",
        checkResult:"合格",
        checkTime:"2024-05-28 09:44:13",
        checkNum:"5",
        quantity:"5",
        unQuantity:"0",
        badMaterialName:"欧变内充气柜"
    },
    {
        orderNum:"CPJY24050021",
        status:"生效",
        productName:"户外环网箱",
        productCode:"CP2405052",
        checkResult:"合格",
        checkTime:"2024-05-27 16:34:42",
        checkNum:"5",
        quantity:"5",
        unQuantity:"0",
        badMaterialName:"户外环网箱"
    },
    {
        orderNum:"CPJY24050017",
        status:"生效",
        productName:"户外环网箱",
        productCode:"CP2405052",
        checkResult:"合格",
        checkTime:"2024-05-23 20:00:53",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"户外环网箱"
    },
    {
        orderNum:"CPJY24050010",
        status:"完成",
        productName:"电缆分支箱",
        productCode:"CP0041",
        checkResult:"合格",
        checkTime:"2024-05-15 10:58:54",
        checkNum:"0",
        quantity:"100",
        unQuantity:"0",
        badMaterialName:"电缆分支箱"
    },
    {
        orderNum:"CPJY24050009",
        status:"完成",
        productName:"10kV箱式变电站",
        productCode:"CP0005",
        checkResult:"合格",
        checkTime:"2024-05-15 10:57:51",
        checkNum:"0",
        quantity:"100",
        unQuantity:"0",
        badMaterialName:"10kV箱式变电站"
    },
    {
        orderNum:"CPJY24050008",
        status:"生效",
        productName:"高压开关柜",
        productCode:"CP0002",
        checkResult:"",
        checkTime:"2024-05-15 10:45:56",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"高压开关柜"
    },
    {
        orderNum:"CPJY24050007",
        status:"完成",
        productName:"高压开关柜",
        productCode:"CP0002",
        checkResult:"合格",
        checkTime:"2024-05-15 10:45:01",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"高压开关柜"
    },
    {
        orderNum:"CPJY24040037",
        status:"生效",
        productName:"10kV箱式变电站",
        productCode:"CP0004",
        checkResult:"",
        checkTime:"2024-04-28 16:17:57",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"10kV箱式变电站"
    },
    {
        orderNum:"CPJY24040035",
        status:"完成",
        productName:"电能计量箱",
        productCode:"CP0033",
        checkResult:"合格",
        checkTime:"2024-04-28 16:15:13",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"电能计量箱"
    },
    {
        orderNum:"CPJY24040034",
        status:"完成",
        productName:"电能计量箱",
        productCode:"CP0033",
        checkResult:"合格",
        checkTime:"2024-04-28 16:11:39",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"电能计量箱"
    },
    {
        orderNum:"CPJY24040033",
        status:"完成",
        productName:"电能计量箱",
        productCode:"CP0033",
        checkResult:"合格",
        checkTime:"2024-04-28 16:10:27",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"电能计量箱"
    },
    {
        orderNum:"CPJY24040032",
        status:"完成",
        productName:"电能计量箱",
        productCode:"CP0033",
        checkResult:"合格",
        checkTime:"2024-04-28 14:31:10",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"电能计量箱"
    },
    {
        orderNum:"CPJY24040014",
        status:"生效",
        productName:"电能计量箱",
        productCode:"CP0033",
        checkResult:"",
        checkTime:"2024-04-26 17:02:37",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"电能计量箱"
    },
    {
        orderNum:"CPJY24040012",
        status:"完成",
        productName:"电能计量箱",
        productCode:"CP0033",
        checkResult:"",
        checkTime:"2024-04-25 18:51:38",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"电能计量箱"
    },
    {
        orderNum:"CPJY24040004",
        status:"生效",
        productName:"电缆分支箱",
        productCode:"CP0041",
        checkResult:"",
        checkTime:"2024-04-25 18:51:38",
        checkNum:"0",
        quantity:"0",
        unQuantity:"0",
        badMaterialName:"电缆分支箱"
    }
];